/**
 * ControleFuncionario ControleFuncionario.java
 */

package CCT220_Trabalho05_13106_Q2.control;


import java.util.ArrayList;

import CCT220_Trabalho05_13106_Q2.model.Funcionario;
import CCT220_Trabalho05_13106_Q2.model.Professor;
import CCT220_Trabalho05_13106_Q2.model.TecAdmin;
import CCT220_Trabalho05_13106_Q2.view.LimiteFuncionario;


/**
 * </br>******************************
 * </br>Project: CCT220
 * </br>Package: CCT220_Trabalho05_13106_Q2.control
 * </br>Class: ControleFuncionario
 * </br>Last Change: 11/10/2011 22:38:52 by marcel
 * </br>Description:
 * </br>******************************</br>
 * 
 * @author marcel
 * @author 13106
 * 
 */
public class ControleFuncionario {
	/**
	 * ArrayList<Funcionario>
	 */
	private final ArrayList<Funcionario> listaFuncionario;
	private final LimiteFuncionario      limFuncionario;


	/**
	 * </br>******************************
	 * </br>Constructor for
	 * </br>Package: CCT220_Trabalho05_13106_Q2.control
	 * </br>Class: ControleFuncionario
	 * </br>LastChange: 11/10/2011 22:40:54 by marcel
	 * </br>******************************</br>
	 * 
	 * @param listaFuncionario
	 */
	public ControleFuncionario() {

		super();
		this.listaFuncionario = new ArrayList<Funcionario>();
		this.limFuncionario = new LimiteFuncionario();
	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Trabalho05_13106_Q2.control
	 * </br>Class: ControleFuncionario
	 * </br>Method: run
	 * </br>Last Change: 11/10/2011 23:24:28 by marcel
	 * </br>Description:
	 * </br>******************************</br>
	 * 
	 */
	public void run() {

		while (true) {
			switch (this.limFuncionario.montaMenuPrincipal()) {
				case 1:
					this.callAddFuncionario(this.limFuncionario
					        .montaMenuAddFuncionario());
					break;
				case 2:
					this.callAddMonthPoint(this.limFuncionario.selectCode(this
					        .getCodeList()));
					break;
				case 3:
					this.callPrintMonthSheet(this.limFuncionario.selectMonth());
					break;
				case 4:
					System.exit(0);
					break;
				default:
					break;
			}
		}
	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Trabalho05_13106_Q2.control
	 * </br>Class: ControleFuncionario
	 * </br>Method: callAddFuncionario
	 * </br>Last Change: 11/10/2011 23:01:21 by marcel
	 * </br>Description:
	 * </br>******************************</br>
	 * 
	 * @param montaMenuAddFuncionario
	 */
	private void callAddFuncionario(boolean isProfessor) {

		if (isProfessor) {
			String v[] = limFuncionario.captureProfessorData();
			listaFuncionario.add(new Professor(Integer.parseInt(v[0]), v[1],
			        v[2], Double.parseDouble(v[3]), Integer.parseInt(v[4])));
		} else {
			String t[] = limFuncionario.captureTecAdminData();
			listaFuncionario.add(new TecAdmin(Integer.parseInt(t[0]), t[1],
			        t[2], Double.parseDouble(t[3])));
		}

	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Trabalho05_13106_Q2.control
	 * </br>Class: ControleFuncionario
	 * </br>Method: callAddMonthPoint
	 * </br>Last Change: 11/10/2011 23:17:56 by marcel
	 * </br>Description:
	 * </br>******************************</br>
	 * 
	 * @param selectCode
	 */
	private void callAddMonthPoint(int selectCode) {

		String s[] = this.limFuncionario.getMonthPoint();

		for (Funcionario f : listaFuncionario) {
			if (f.getCodigo() == selectCode) {
				f.adicionaPonto(Integer.parseInt(s[0]), Integer.parseInt(s[1]));
				f.lancaFaltas(Integer.parseInt(s[0]), Integer.parseInt(s[1]),
				        Integer.parseInt(s[2]));
				f.lancaAtrasos(Integer.parseInt(s[0]), Integer.parseInt(s[1]),
				        Integer.parseInt(s[3]));
			}
		}

	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Trabalho05_13106_Q2.control
	 * </br>Class: ControleFuncionario
	 * </br>Method: callPrintMonthSheet
	 * </br>Last Change: 11/10/2011 23:30:55 by marcel
	 * </br>Description:
	 * </br>******************************</br>
	 * 
	 * @param selectTime
	 */
	private void callPrintMonthSheet(String[] selectTime) {

		ArrayList<String> list = new ArrayList<String>();
		list.add("\nFolha de " + selectTime[0] + "/" + selectTime[1] + "\n");
		for (Funcionario f : listaFuncionario) {
			String str = "";
			if (!f.getPontoMensal().isEmpty()) {
				str += "\nFuncionario: " + f.getNome() + "-" + f.getCodigo();
				str += f.imprimeFolha(Integer.parseInt(selectTime[0]), Integer
				        .parseInt(selectTime[1]));

			}
		}

	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Trabalho05_13106_Q2.control
	 * </br>Class: ControleFuncionario
	 * </br>Method: getCodeList
	 * </br>Last Change: 11/10/2011 23:12:49 by marcel
	 * </br>Description:
	 * </br>******************************</br>
	 * 
	 * @return
	 */
	private String getCodeList() {

		String ret = "[";
		for (Funcionario f : listaFuncionario) {
			ret += " " + f.getCodigo() + ",";
		}
		ret = ret.substring(0, ret.length() - 1);
		ret += " ]";
		return ret;
	}

}
